#pragma once

#include "resource.h"
#include "afxmt.h"

#define WDF_SECTION_NAME L"dnsfilter_Device.NT.Wdf"
#define SERVICE_SECTION_NAME _T("dnsfilter_Device.NT.Services")
#define SERVICE_DELETE_SECTION_NAME _T("dnsfilter_Device.NT.Services.Delete")
#define DRIVER_SERVICE_NAME _T("dnsfilter")
#define DEVICE_KEY _T("SYSTEM\\CurrentControlSet\\Enum\\Root\\LEGACY_DNSFILTER")
#define DEVICE_KEY_INSTANCE _T("Root\\LEGACY_DNSFILTER\\0000")
#define DEVICE_ID_HARDWARE _T("Root\\dnsfilter")

enum EPageState
{
    enNoLoadState,
    enDeletePendedState,
    enUninstallPageState,
    enPage1State,
    enPage2State,
    enPage3State,
    enRemoveInfPageState,
    enInstallDriverPageState,
    enPage9State,
    enWdfInstallRebootPage,
    enInstallRebootPage1
};

enum ERebootPurpose : int
{
    enNoReboot = 0,
    enSetTesting,
    enWdfInstall,
    enDriverStore,
    enDriverService,
    enStopPluginService,
    enDeletePluginService,
    enStopDriverService,
    enDeleteDriverService,
    enDeleteDriverFile
};

// CDriversInstallApp
class CInstallDialog;
class CDriversInstallApp : public CWinApp
{
public:
	CDriversInstallApp();
	virtual ~CDriversInstallApp();

public:
	virtual BOOL InitInstance();
	virtual int ExitInstance();

protected:
	DECLARE_MESSAGE_MAP()
public:
    bool m_bInstallDriver;
    bool m_bUninstallDriver;
    bool m_bQuiet;
    CString m_sInfFilePath;
    bool m_bUsageOut;
    bool m_bParseError;
    int m_nRetCode;
    CString m_sVersionHTMLString;
    CString m_sCopyRightDates;
    CString m_sModuleFileName;
    CString m_sModuleFolder;
    ULONGLONG m_qwFileVersion;
    CString m_sStartPageName;
    CInstallDialog* m_pMainDialog;
    bool m_bRebootNeed;
    EPageState m_ePageState;
    CString m_sForwardImageSRC;
    CString m_sDriverFolder;
    CString m_sCoInstallerPath;
    CEvent m_oDriverInstallDoneEvent;
    bool m_bTestModeInstalling;
    bool m_bTestModeInstalled;
    bool m_bRootCertExist;
    bool m_bRootCertInstalled;
    bool m_bTrustedPublisherCertExist;
    bool m_bTrustedPublisherCertInstalled;
    HMODULE m_hCoInatallerModule;
    PFN_WDFPREDEVICEINSTALL m_pfnWdfPreDeviceInstall;
    PFN_WDFPOSTDEVICEINSTALL m_pfnWdfPostDeviceInstall;
    PFN_WDFPREDEVICEINSTALLEX m_pfnWdfPreDeviceInstallEx;
    PFN_WDFPREDEVICEREMOVE m_pfnWdfPreDeviceRemove;
    PFN_WDFPOSTDEVICEREMOVE m_pfnWdfPostDeviceRemove;
    CString m_sDriversFolder;
    ERebootPurpose m_enRebootPurpose;
    void mfDeleteKey(
        HKEY hRootKey,
        LPCTSTR szKeyPath
        );
    PACL m_pDeviceKeyDacl;
    bool SetProcessPrivilege(
        LPCTSTR lpszPrivilege,
        bool bEnablePrivilege);
    HANDLE m_hProcessToken;
    SID* m_pAdminsSid;
    BYTE m_abAdminsSidBuffer[SECURITY_MAX_SID_SIZE];
    DWORD m_dwAdminsSidSize;
    SID* m_pWorldSid;
    BYTE m_abWorldSidBuffer[SECURITY_MAX_SID_SIZE];
    DWORD m_dwWorldSidSize;
	CString m_sOEMInfFile;
};

extern CDriversInstallApp theApp;
